package com.uxhao.eduservice.controller;


import com.uxhao.commonutils.R;
import com.uxhao.eduservice.entity.vo.SubjectNestedVo;
import com.uxhao.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 课程科目 前端控制器
 * @author uxhao
 * @since 2022/01/10
 */
@Api(tags={"课程分类管理"})
@RestController
//@CrossOrigin
@RequestMapping("/eduservice/subject")
public class EduSubjectController {

    @Autowired
    private EduSubjectService subjectService;

    //获取excel表格 读取内容加载到数据库
    @ApiOperation("添加课程分类")
    @PostMapping("addSubject")
    @CacheEvict(value = "eduSubject",allEntries=true)//清空
    public R addSubject(MultipartFile file){

        subjectService.saveSubject(file,subjectService );
        return R.ok();
    }
    @ApiOperation("课程分类列表[树形]")
    @GetMapping("getSubject")
    public R getSubject(){
        List<SubjectNestedVo> list = subjectService.getAllSubject();
        return R.ok().data(list);
    }
}

